<?php ob_start(); header('Cache-Control: no-store, no-cache, must-revalidate');


	$query = "SELECT * FROM bike_schema.mapdir WHERE flagRoute = '1'";  // query from the data table

    while ($row = mysql_fetch_array($res, MYSQL_ASSOC))
    {
    	array_push($routes, $row["value"]);
    	array_push($routeType, $row["routeType"]);
    	array_push($description, $row["description"]);
   	}
	// encode the Array of objects into an array of strings
	$encodedRoutes = json_encode($routes);


<script>

//Following is for the waypoints using direction services

	var arrayRoutes = <? echo $encodedRoutes; ?>;   // json encoded string array

	// store all the routes
	for(var i=0; i<size; i++)
	{
    	var tempRoute = JSON.stringify(eval('('+arrayRoutes[i]+')')); // get individual element from the array
		var obj = JSON.parse(tempRoute);       // convert that json string into an object
		allRoutes.push(obj);                // store that object
	}

	var polylineOptionsActual = { strokeColor: routeColor, strokeOpacity: 1.0, strokeWeight: 4 };
	renArray[i] = new google.maps.DirectionsRenderer( {
		'draggable':false,
		polylineOptions: polylineOptionsActual,
		suppressMarkers:true
		});
	renArray[i].setMap(map);
	serArray[i] = new google.maps.DirectionsService();
	setAllRoute(allRoutes,i);




function setAllRoute(allRoutes,index)
{
	var wp = [];
	for(var i=0;i<allRoutes[index].waypoints.length;i++)
		wp[i] = {'location': new google.maps.LatLng(allRoutes[index].waypoints[i][0], allRoutes[index].waypoints[i][1]),'stopover':false }

	serArray[index].route({'origin':new google.maps.LatLng(allRoutes[index].start.lat,allRoutes[index].start.lng),
	'destination':new google.maps.LatLng(allRoutes[index].end.lat,allRoutes[i].end.lng),
	'waypoints': wp,
	'travelMode': google.maps.DirectionsTravelMode.BICYCLING},function(res,sts) {
		if(sts=='OK')renArray[index].setDirections(res);
	})

}
